package org.elucid.chess;

import java.util.List;
import java.util.Random;

import org.elucid.chess.model.Game;
import org.elucid.chess.model.Move;

/**
 * This class implements the Player interface for the CPU Evaluator
 * 
 * @author george
 *
 */
public class CpuPlayer extends AbstractPlayer {

	private Thread evalThread;
	Random random = new Random();
	
	public CpuPlayer(Boolean isWhite, Game game) {
		super(isWhite, game);
	}
	
	public void start()
	{
		evalThread = new Evaluator();
		evalThread.start();
	}
	
	@Override
	public Move chooseMove() throws Exception {
		
		Thread.sleep(500); // slow down CPU move
		
		List<Move> moves = game.listLegalMoves();
		return moves.size() > 0 ? moves.get( random.nextInt( moves.size() ) ) : null;
	}

	
	public String toString()
	{
		return String.format("CPU Player [%s]", this.isWhite ? "white":"black");
	}
	
}
